package com.xiaoxi.bridgemode.realization;

import java.io.BufferedInputStream;
import java.io.IOException;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.bridgemode.realization
 * @ClassName StringDisplayImpl
 * @Description TODO
 * @Date 2023/3/13 19:54
 * @Version 1.0
 */
public class FileDisplayImpl implements DisplayImpl {

    private BufferedInputStream bufferedInputStream;

    public FileDisplayImpl(BufferedInputStream bufferedInputStream) {
        this.bufferedInputStream = bufferedInputStream;
    }

    @Override
    public void rawOpen() {
        System.out.println("~~~~~~~~~~~~~~~读取文件开始~~~~~~~~~~~~");
    }

    @Override
    public void rawPrint() {
        int len;
        byte[] bytes = new byte[1024];
        try {
            while ((len = bufferedInputStream.read(bytes)) != -1) {
                System.out.println(new String(bytes, 0, len));
            }
        } catch (IOException e) {
            System.out.println("输入流出错：" + e.getMessage());
        }

    }

    @Override
    public void rawClose() {
        System.out.println("~~~~~~~~~~~~~~~读取文件结束~~~~~~~~~~~~");
    }

}
